﻿@using SAB.Domain.User;
@using SAB.Domain.Politica;
@using SAB.Domain.Library;
@{
    ViewBag.Title = "Buscar Personal";
}

<div class="row">
    <div class="col-md-12">
        <ol class="breadcrumb">
            <li>@Html.ActionLink("Home", "Index", "Home")</li>
            <li>@Html.ActionLink("Personal", "SearchPersonalResult", "Personal")</li>
            <li class="active">Buscar </li>
        </ol>
    </div>
</div>
@section Scripts
{
    <script src="@Url.Content("~/Scripts/UserAccount.js")"></script>



}

<div class="col-md-10">
    <div class="pull-right">
        <a href="@Url.Content("~/Account/CreatePersonal")" class="btn btn-primary">
            <i class="glyphicon glyphicon-plus"></i> Nuevo Empleado
        </a>
    </div>
</div>
<br>

<div class="row">
    <div class="col-md-12 title">
        <h1>Búsqueda Personal</h1>

    </div>
</div>

@{IEnumerable<UserProfile> perfiles = (IEnumerable<UserProfile>)ViewData["perfiles"];}
@{IEnumerable<Local> bibliotecas = (IEnumerable<Local>)ViewData["bibliotecas"];}
@{IEnumerable<UserAccount> usuarios = (IEnumerable<UserAccount>)ViewData["usuarios"]; }
<div class="col-md-10">
    @if (TempData["message"] != null)
    {
        <div class="alert alert-success" role="alert">@TempData["message"]</div>
    }
    @if (TempData["alert"] != null)
    {
        <div class="alert alert-danger" role="alert">@TempData["alert"]</div>
    }

</div>

<div class="col-md-10">

    <form action="@Url.Action("SearchResultPersonal", "Account")" method="post" id="PRS_SearchForm">
        <div class=" form-group">
            <div class="row">
                <div class="col-md-6">
                    <label for="exampleInputEmail1">Código</label>
                    <input type="number" name="searchCode" value="@ViewData["searchCode"]" min="1" class="form-control" id="exampleInputEmail1" placeholder="">
                </div>
                <div class="col-md-6">
                    <label for="exampleInputEmail1">Número de Documento</label>
                    <input type="text" name="searchDNI" value="@ViewData["searchDNI"]" class="form-control" id="exampleInputEmail1" placeholder="" pattern="[a-zA-Z0-9_]*" title="Please enter valid characters">
                </div>

            </div>
        </div>

        <div class="form-group">
            <div class="row">


                <div class="col-md-6">
                    <label for="tipo">Tipo Empleado</label>
                    <select name="tipo" class="form-control">
                        <option value="0" selected>Todos</option>
                        @{

                            int i = 1;
                            foreach (UserProfile r in perfiles)
                            {
                                if ((int)ViewData["tipo"] == r.Id) { 
                                <option value="@r.Id" selected>@r.Name</option>}
                                else { 
                                    <option value="@r.Id">@r.Name</option>
                                }
                                i++;
                            }
                        }
                    </select>
                </div>

                <div class="col-md-6">
                    <label for="tipo">Local</label>
                    <select name="biblioteca" class="form-control">
                        @{
                            <option value="0" selected>Todos</option>

                            foreach (Local r in bibliotecas)
                            {
                                if ((int)ViewData["biblioteca"] == r.Id) { 
                                <option value="@r.Id" selected >@r.Name</option>}
                                else { 
                                    <option value="@r.Id">@r.Name</option>
                                }

                            }
                        }
                    </select>
                </div>


            </div>
        </div>

        <div class="form-group">
            <div class="row">
                <div class="col-md-6">
                    <label for="exampleInputEmail1">Nombres</label>
                    <input type="text" name="searchName" value="@ViewData["searchName"]" class="form-control" placeholder="" maxlength="25" pattern="[a-zA-Z0-9 ]*" title="solo letras y espacios">
                </div>

                <div class="col-md-6">
                    <label for="exampleInputEmail1">Apellidos</label>
                    <input type="text" name="searchApellido" value="@ViewData["searchApellido"]" maxlength="25" class="form-control" pattern="[a-zA-Z0-9 ]*" title="solo letras y espacios">
                </div>
            </div>
        </div>
        |
        <div class="form-group">
            <div class="row">
                <div class="col-md-6">
                    <label for="searchText">Fecha de Registro desde:</label>
                    <input type="text" name="from" value="@ViewData["from"]" placeholder="Búsqueda ..." class="form-control generic-datepicker">
                </div>
                <div class="col-md-6">
                    <label for="searchText">Fecha de Registro hasta:</label>
                    <input type="text" name="to" value="@ViewData["to"]" placeholder="Búsqueda ..." class="form-control generic-datepicker">
                </div>
            </div>
        </div>






        <div class="col-sm-12" style="height:30px;"></div>
        <div class="form-group">
            <div>
                @if (ViewData["pageIndex"] != null)
                {

                    <input type="hidden" value="@((int)(ViewData["pageIndex"]))" name="pageIndex" id="PRS_pageIndex" class="form-control">

                }
                else
                {
                    <input type="hidden" value="1" name="pageIndex" id="PRS_pageIndex">
                }
            </div>
            <button class="btn btn-primary pull-right" type="submit" id="btnSearch">Buscar</button>

        </div>
    </form>
</div>

<form action="@Url.Action("SearchPersonalResultDetail", "Account")" class="form-horizontal" method="post" role="form">
    <div class="col-md-10">
        <div class="row">

            <table class="table-responsive table table-striped">
                <tr>
                    <th class="cod">Código</th>
                    <th class="fechaDeRegistro">Fecha de Registro</th>
                    <th class="nombres">Nombres</th>
                    <th class="tipoEmpleado">Tipo de Empleado</th>
                    <th class="text-center"> </th>
                </tr>

               @{

                if (usuarios != null)
                {
                    foreach (UserAccount r in usuarios)
                    {
                        <tr>
                            <td>@r.Id</td>
                            <td>@r.RegisterDate.ToShortDateString()</td>
                            <td>@r.Name</td>
                            <td>@r.TipoPerfil.Name</td>

                            <td>
                                <a href="@Url.Action("SearchPersonalResultDetail", "Account", new { id = @r.Id })"><i class="margin-right-icon glyphicon glyphicon-zoom-in"></i></a>
                                <a href="@Url.Action("ModifyAccount", "Account", new { id = @r.Id })"><i class="margin-right-icon glyphicon glyphicon-pencil"></i></a>
                                <a class="DeleteUserAccount" data-id="@r.Id"><i class="margin-right-icon glyphicon glyphicon-remove" data-toggle="modal" data-target="#deleteModal"></i></a>

                            </td>
                        </tr>
                    }
                }

                }
                
            </table>

            <div class="col-md-12 col-md-offset-3 form-horizontal">
                <div class="form-group ">
                    <div>
                        <ul class="pagination">
                            <li><a id="PRS_btnFirst">Primero</a></li>
                            <li><a id="PRS_btnPrev">&laquo;</a></li>

                            <li>
                                @if (ViewData["pageIndex"] != null)
                                {
                                    int pageIndex = (int)ViewData["pageIndex"];
                                    <span>@pageIndex</span>

                                }
                                else
                                {
                                    <span>1</span>
                                }
                            </li>
                            <li><a id="PRS_btnNext">&raquo;</a></li>
                            <li><a id="PRS_btnLast">Último</a></li>
                        </ul>
                    </div>



                </div>
            </div>

        </div>
    </div>





</form>


<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">Confirmación</h4>
            </div>
            <div class="modal-body">
                <div>
                    <label class="control-label">
                        <!--for="inputFechaInicio" class="control-label"-->
                        ¿Estas seguro que quieres Eliminar
                    </label>
                    <label class="control-label">
                        este Usuario?
                    </label>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
                <button id="btnAcceptDeleteUserAccount" data-dismiss="modal" class="btn btn-primary">Aceptar</button>
            </div>

        </div>
    </div>
</div>
